﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using COC.Commons;

namespace COC.Tool
{
    public partial class TaskCommentListView : Form
    {

        private readonly PlanTask _PlanTask;

        public TaskCommentListView(PlanTask pt)
        {
            InitializeComponent();
            this._PlanTask = pt;
            IDText.Text = pt.Id;
            TypeText.Text = pt.Type;
            StateText.Text = pt.State;
            ContentText.Text = pt.Content;
            FreshenCommentListView();
        }

        private void AddComment_Click(object sender, EventArgs e)
        {
            AddCommentView addCommentView = new AddCommentView(_PlanTask);
            //这里应该addCommentView取得了_PlanTasks自己做显示
            addCommentView.ShowDialog();
            FreshenCommentListView();
        }

        private void FreshenCommentListView()
        {
            CommentList?.Items.Clear();
            if (_PlanTask.Comments.Count <= 0) return;
            foreach (var co in _PlanTask.Comments)
            {
                var lvi = new ListViewItem(co.Id);
                lvi.SubItems.Add(co.Time);
                lvi.SubItems.Add(co.Content);
                CommentList?.Items.Add(lvi);
            }
        }
    }
}